/**************************************************************************
 *                                                                        *
 *         Copyright (c) 2007 by Sunplus mMedia Inc.                      *
 *                                                                        *
 *  This software is copyrighted by and is the property of Sunplus        *
 *  mMedia Inc. All rights are reserved by Sunplus mMedia Inc.  This      *
 *  software may only be used in accordance with the corresponding        *
 *  license agreement. Any unauthorized use, duplication, distribution,   *
 *  or disclosure of this software is expressly forbidden.                *
 *                                                                        *
 *  This Copyright notice MUST not be removed or modified without prior   *
 *  written consent of Sunplus mMedia Inc.                                *
 *                                                                        *
 *  Sunplus mMedia Inc. reserves the right to modify this software        *
 *  without notice.                                                       *
 *                                                                        *
 *  Sunplus mMedia Inc.                                                   *
 *  19-1, Innovation First Road, Science-Based Industrial Park,           *
 *  Hsin-Chu, Taiwan, R.O.C.                                              *
 *                                                                        *
 **************************************************************************/

#ifndef _ctlsetup_h_
#define _ctlsetup_h_
//------------------------------------------------------------------------------
//Constant
//------------------------------------------------------------------------------
//Standard Request Code
#define K_STDREQCODE_GET_STATUS         0x00
#define K_STDREQCODE_CLEAR_FEATURE      0x01
#define K_STDREQCODE_SET_FEATURE        0x03
#define K_STDREQCODE_SET_ADDRESS        0x05
#define K_STDREQCODE_GET_DESCRIPTOR     0x06
#define K_STDREQCODE_SET_DESCRIPTOR     0x07
#define K_STDREQCODE_GET_CONFIGURATION  0x08
#define K_STDREQCODE_SET_CONFIGURATION  0x09
#define K_STDREQCODE_GET_INTERFACE      0x0A
#define K_STDREQCODE_SET_INTERFACE      0x0B
#define K_STDREQCODE_SYNCH_FRAME        0x0C
//Descriptor Type
#define K_DEVICE_DESCRIPTOR             0x0100
#define K_CONFIGURATION_DESCRIPTOR      0x0200
#define K_STRING_DESCRIPTOR             0x0300
#define K_INTERFACE_DESCRIPTOR          0x0400
#define K_ENDPOINT_DESCRIPTOR           0x0500
#define K_DEVICE_QUALIFIER_DESCRIPTOR   0x0600
#define K_OTHERSPEED_DESCRIPTOR   		0x0700
//Phase of Transfer
#define K_CommandPhase                  0x00
#define K_OutDataPhase                  0x01
#define K_OutDataPhaseWrite             0x02
#define K_OutResponsePhase              0x03
#define K_InDataPhase                   0x81
#define K_InDataPhaseRead               0x82
#define K_InResponsePhase               0x83
#define K_InCompletionPhase             0x84
#define K_XferDirMask                   0x80



//------------------------------------------------------------------------------
//Type Definition
//------------------------------------------------------------------------------
#define K_CTRL_COMMAND_SIZE     0x08
typedef struct _CTRL_COMMAND
{
        UINT8   bmRequestType;
        UINT8   bRequest;
        UINT16  wValue;
        UINT16  wIndex;
        UINT16  wLength;
} CTRL_COMMAND, *PCTRL_COMMAND;

//------------------------------------------------------------------------------
//External Link
//------------------------------------------------------------------------------
extern  PCTRL_COMMAND   G_pCtrlCommand;

extern  xdata   UINT16  G_usCtrlDataLength;
extern  xdata   UINT16  G_usCtrlDataIndex;
extern  xdata   UINT8   G_ucCtrlPacketIndex;
extern  xdata   UINT8   G_ucCtrlPhase;
extern  xdata   UINT8   G_UsbConnectStatus;

extern  code    UINT8   DeviceDescriptor[];
extern  code    UINT8   ConfigurationDescriptor[];

//------------------------------------------------------------------------------
//Function Prototype
//------------------------------------------------------------------------------
void CTLSETUP_Packet(void);
void CTLSETUP_StandardRequest(void);
void CTLSETUP_ClassRequest(void);
void CTLSETUP_VendorRequest(void);
void CTLSETUP_ReservedRequest(void);
void CTLSETUP_GetSetupPacket(void);

#endif /*_ctlsetup_h_*/
